package d集合.day2.map.demo1_HashMap;

import java.util.*;

public class Test1 {
    public static void main1(String[] args) {
        HashMap hm=new HashMap();
        hm.put("张三",98);
        hm.put("李四",89);
        hm.put("李四",100);
        System.out.println(hm.containsKey("张三"));
        hm.remove("李四");
        System.out.println(hm);
    }

    public static void main(String[] args) {
        HashMap<String,Integer> m=new HashMap<>();
        m.put("a1",135);
        m.put("a2",124);
        m.put(null,null);

        System.out.println(m.size());

        Integer v=m.get("a1");
        System.out.println("=================遍历方法一================");
        Set<String> keys=m.keySet();
        for (String k:keys){
            System.out.println(k+":"+m.get(k));
        }
        System.out.println("=================遍历方法二================");
        Collection<Integer> values=m.values();
        for (Integer i:values){
            System.out.println(i);
        }
        System.out.println("==============遍历方法三=================");
        Set<Map.Entry<String,Integer>> set=m.entrySet();
        for(Map.Entry<String,Integer> e:set){
            System.out.println(e.getKey() + ":" + e.getValue());
        }
        System.out.println("==============遍历方法四=================");
        Set<Map.Entry<String,Integer>> sets=m.entrySet();
        Iterator<Map.Entry<String,Integer>> it=sets.iterator();
        while (it.hasNext()){
            Map.Entry e=it.next();
            System.out.println(e.getKey() + ":" + e.getValue());
        }


    }
}
